﻿using ArtMath.Attribute;
using ArtMath.Core.Data;
using ArtMath.Data;
using System;
using System.ComponentModel;

namespace ArtMath.Component.Line
{
    /// <summary>
    /// 中垂线
    /// </summary>
    [Serializable]
    public class PerpendicularBisector : PointSlopeLineBase
    {
        LineSegmentBase line;
        public PerpendicularBisector(SketchPad pad, string name, LineSegmentBase line, bool addToList = true) : base(pad, name, ToolTypeName.zcx, addToList)
        {
            LineSegment = line;
        }

        [MultilingualCategory("Structure"), MultilingualDisplayName("LineSegment"), TypeConverter(typeof(ExpandableObjectConverter))]
        public LineSegmentBase LineSegment
        {
            get { return line; }
            set
            {
                line?.OutChildren_Line.Remove(this);
                line = value;
                line?.OutChildren_Line.Add(this);
            }
        }
        public override PointD NewLocation
        {
            get
            {
                return (LineSegment.Point1.NewXY + LineSegment.Point2.NewXY) / 2;
            }
        }
        public override PointD NewPLocation
        {
            get
            {
                return (LineSegment.Point1.NewPxy + LineSegment.Point2.NewPxy) / 2;
            }
        }
        public override double NewSlope
        {
            get
            {
                return -1 / LineSegment.NewSlope;
            }
        }
        public override double NewPSlope
        {
            get
            {
                return Pad.GetVerticalLinePSlope(LineSegment.Point1.NewPxy, LineSegment.Point2.NewPxy);
            }
        }
        [Browsable(false)]
        public override AngleStringX RotateAngle
        {
            get
            {
                return base.RotateAngle;
            }

            set
            {
                base.RotateAngle = value;
            }
        }
        [Browsable(false)]
        public override RPointS RotateCenter
        {
            get
            {
                return base.RotateCenter;
            }

            set
            {
                base.RotateCenter = value;
            }
        }
        public override PointD AnchorPoint(PropertyDisplayer disp)
        {
            return pske.Location;
        }
        public override void CreateComponents()
        {
            ske.Location = (LineSegment.Point1.ToPointD() + LineSegment.Point2.ToPointD()) / 2;
            pske.Location = (LineSegment.Point1.Pxy + LineSegment.Point2.Pxy) / 2;
            Slope = -1 / LineSegment.Slope;
            base.CreateComponents();
        }
    }
}
